<?php

/* CAT:Line chart */

/* pChart library inclusions */

$pchart_basepath = 'application/third_party/pchart/';

include($pchart_basepath . 'class/pData.class.php');
include($pchart_basepath . 'class/pDraw.class.php');
include($pchart_basepath . 'class/pImage.class.php');

$x_axis = array();

foreach ($data[1] as $key => $value) {
    $x_axis[] = $key;
}

/* Create and populate the pData object */
$dataset = new pData();
$dataset->addPoints($data[1], 'Sammy');
$dataset->addPoints($data[2], 'Ery');
$dataset->addPoints($data[3], 'Yudi');
$dataset->setSerieTicks('Probe 2', 4);
$dataset->setSerieWeight('Probe 3', 2);
$dataset->setAxisName(0, 'Amount (IDR x1000)');
$dataset->addPoints($x_axis, 'Labels');
$dataset->setSerieDescription('Labels', 'Months');
$dataset->setAbscissa('Labels');


/* Create the pChart object */
$chart = new pImage(460, 300, $dataset);

/* Turn of Antialiasing */
$chart->Antialias = FALSE;

/* Write the chart title */
$chart->setFontProperties(array('FontName' => $pchart_basepath . 'fonts/Forgotte.ttf', 'FontSize' => 11));
$chart->drawText(150, 35, 'Expense for Last 7 Days', array('FontSize' => 20, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE));

/* Set the default font */
$chart->setFontProperties(array('FontName' => $pchart_basepath . 'fonts/pf_arma_five.ttf', 'FontSize' => 6));

/* Define the chart area */
$chart->setGraphArea(30, 40, 450, 280);

/* Draw the scale */
$scaleSettings = array('XMargin' => 10, 'YMargin' => 10, 'Floating' => TRUE, 'GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => TRUE, 'CycleBackground' => TRUE);
$chart->drawScale($scaleSettings);

/* Turn on Antialiasing */
$chart->Antialias = TRUE;

/* Draw the line chart */
$chart->drawSplineChart();

/* Write the chart legend */
$chart->drawLegend(330, 20, array('Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_HORIZONTAL));

/* Render the picture (choose the best way) */
$chart->autoOutput('chart.png');
?>
